package com.lnking.lnkingplace.model.dto.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lnking.lnkingplace.Util.DataDesensitizedUtils;
import com.lnking.starter.mybatis.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;

@Data
public class UserDto extends BaseEntity {

    private String name;
    private String phone;
    private String type;
    private String channel;
    private String idCard;
    private String sex;
    private String nativePlace;
    private String address;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private LocalDateTime entryTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime resultTime;
    private String placeId;
    private String placeName;
    private String position;
    private String placeType;
    private String street;
    private String education;
    private String urgentName;
    private String urgentPhone;
    private String disease;
    private String  photos;
    private String qrcode;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime creatorTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastRecordTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastCheckTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime checkTime;

    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")

    @ApiModelProperty(value = "房间号")
    private String roomNumber;

    public LocalDateTime getRecordTime() {

        // 云从采样时间
        if(lastRecordTime!=null&&lastRecordTime.isAfter(LocalDateTime.now().minusHours(configDay+1))){
                return  lastRecordTime;

        }else if(checkTime!=null&&checkTime.isAfter(LocalDateTime.now().minusHours(configDay+1))){
                return  checkTime;
        }else if (lastRecordTimeByManual!=null&&lastRecordTimeByManual.isAfter(LocalDateTime.now().minusHours(configDay+1))){
                return  lastRecordTimeByManual;
        }else  {
            return null;
        }
    }



    public LocalDateTime getLastCheckTime() {
        if("是".equals(lastCheckStatus)){
            return checkTime;
        }else{
            return  null;
        }

    }

    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastCheckTimeByManual;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastRecordTimeByManual;
    private String  lastCheckStatus;
    private Integer configDay;
    private Integer diffDate;
    @ApiModelProperty(value = "职务")
    private String duties;

    @ApiModelProperty(value = "部门")
    private String department;

    @ApiModelProperty("是否在岗")
    private String  onDuty;

    private String shopSign;

    private String userType;

    @JsonIgnore
    //脱敏手机号
    private String desensitizationPhone;
    @JsonIgnore
    //脱敏身份证
    private String desensitizationIdCard;

    @JsonIgnore
    private String checkConfig;

    @ApiModelProperty(value = "数据来源")
    private String dataSources;

    public String getCheckConfig() {
        if(null == configDay){
            return "场所未要求";
        }
        else if(null != configDay && (configDay - diffDate) < 0){
            return "超期未做核酸";
        }
        else if(null != configDay && (configDay - diffDate) <= 24){
            return "即将超期";
        }
        return null;
    }

    public String getPhone(){
        return DataDesensitizedUtils.desensitizedPhoneNumber(phone);
    }

    public String getIdCard(){
        return DataDesensitizedUtils.desensitizedIdNumber(idCard);
    }

}
